package Year22_Month04.day09;

public class 有序数组的平方 {
    public int[] sortedSquares(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        for (int i = 0; i < nums.length; i++) {
            nums[i] = nums[i] * nums[i];
        }
        int[] arr = new int[nums.length];
        int index = nums.length - 1;
        //我真的感觉像那个排序算法
        while(index >= 0 && left < right){
            if(nums[left] > nums[right]){
                arr[index] = nums[left];
            }else{
                arr[index] = nums[right];
            }
            index--;
        }
        return arr;
    }
}
